package com.anjubao.parking.municipal.roadside.service;

import com.anjubao.parking.municipal.roadside.constant.CommandConstants;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhuchunfeng
 * @date 2019/6/18 10:18
 */

@Service
public class DeviceOperationService {

    @Resource
    private RedisService redisService;

    /**
     * 6 manualsynctime 手动对时下发
     * 10.1.1 下发命令格式
     * {
     * "cmd":"manualsynctime"，
     * "devid":"123456789001",
     * "id":"123456789012",
     * "second":xxx
     * }
     */
    //6 manualsynctime 手动对时下发
    public void manualSyncTime(String deviceId){
        //下发指令
        redisService.putCmd(deviceId, CommandConstants.MANUALSYNCTIME);
    }

    /**
     * 10.2 手动抓拍
     * 10.2.1 下发命令格式
     * {"cmd":"manualsnapctrl"，"devid":"123456789001","id":"123456789012","channel":0}10.2.2 结果返回值
     * 正常，返回如下数据:返回报警类型为“手动抓拍”的报警数据，具体格式见：5.1 报警上报协议（手动抓拍）。异常，返回如下数据:{"cmd":"manualsnapctrl"，"devid":"123456789001","id":"123456789012","response":"0
     */
    public void manualsnapctrl(String deviceId){
        //下发指令
        redisService.putCmd(deviceId, CommandConstants.MANUALSNAPCTRL);
    }

    /**
     * 10.3 地锁、停车指示灯控制
     * 10.3.1 下发命令格式
     */
    public void mcuctrl( String deviceId, Integer lock,String led){
        Map<String,String> map = new HashMap<>();
        map.put("led",led);
        map.put("lock",lock.toString());
        redisService.putCmdWithParam(deviceId, CommandConstants.MCUCTRL,map);

    }

    /**
     * 10.4 查询视频充电停车设备状态
     */
    public void devquery( String deviceId){
        redisService.putCmd(deviceId, CommandConstants.DEVQUERY);
    }

    /**
     * 10.5 视频充电停车设备重启
     */
    public void devreboot(String deviceId){
        redisService.putCmd(deviceId, CommandConstants.DEVREBOOT);
    }

    /**
     * 二维码下发
     * @param deviceId 设备id
     * @param code 二维码
     * @param type
     *      *  pay:支付二维码
     *      *  app:APP 软件下载二维码
     *      *  charge:充电桩二维码
     */
    public void rqcode(String deviceId, String code, String type) {
        Map<String, String> map = new HashMap<>();
        map.put("code", code);
        map.put("type", type);
        redisService.putCmdWithParam(deviceId, CommandConstants.RQCODE, map);
    }

    /**
     * 泊位号下发
     * @param deviceId 设备id
     * @param id 泊位号
     */
    public void berthnum(String deviceId,String id) {
        Map<String,String> map = new HashMap<>();
        map.put("id",id);
        redisService.putCmdWithParam(deviceId, CommandConstants.BERTHNUM,map);

    }
}
